Public Class UnresolvedData

	Protected m_clearid As Long
	Protected m_clearid2 As Long = 0
	Public ColumnName As String = ""
	Public DataTable As String = ""
	Public DataIdField As String = ""
	Public DataDescField As String = ""
	Public Where As String = ""

	Public ColumnName2 As String = ""
	Public DataIdField2 As String = ""

	Protected dbi As dbInterface = Globals.dbi

#Region "Properties"
#End Region

	Public Sub New(ByVal clearid As Long)
		Me.New(clearid, 0)
	End Sub

	Public Sub New(ByVal clearid As Long, ByVal addlClearid As Long)
		m_clearid = clearid
		m_clearid2 = addlClearid
	End Sub

	Public Sub New(ByVal clearid As Long, ByVal addlClearid As Long, ByVal colName As String, ByVal dtTable As String, ByVal idField As String, _
		ByVal dscField As String, ByVal whereCl As String, ByVal colName2 As String, ByVal idField2 As String)
		m_clearid = clearid
		m_clearid2 = addlClearid
		ColumnName = colName
		DataTable = dtTable
		DataIdField = idField
		DataDescField = dscField
		Where = whereCl
		ColumnName2 = colName2
		DataIdField2 = idField2
	End Sub

	Public Sub Insert()
		If ColumnName = "" Then Exit Sub

		Dim sql As String

		sql = "delete from clearing_unresolved where clear_id=" & m_clearid & " and column_name=" & dbi.quote(ColumnName)

		dbi.nonquery(sql)

		sql = "insert into clearing_unresolved (clear_id, column_name, data_table, data_id_fld, data_desc_fld, data_where_clause,"
		sql &= "addl_column_name, addl_data_id_fld, related_clear_id) values ("
		sql &= m_clearid & "," & dbi.quote(ColumnName) & ","
		sql &= dbi.quote(DataTable) & ","
		sql &= dbi.quote(DataIdField) & ","
		sql &= dbi.quote(DataDescField) & ","
		sql &= dbi.quote(Where) & ","
		sql &= dbi.quote(ColumnName2) & ","
		sql &= dbi.quote(DataIdField2) & ","
		sql &= m_clearid2 & ")"

		dbi.nonquery(sql)

		' make sure the trade shows unresolved data
		sql = "update clearing_trades set clearing_status=" & ClearingStatuses.UnresolvedData.GetHashCode
		sql &= " where clear_id in (" & m_clearid & "," & m_clearid2 & ")"

		dbi.nonquery(sql)
	End Sub
End Class
